package com.chenyun.common.config;

import com.chenyun.common.vo.ApplicationProperties;

import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.math.BigInteger;

/**
 * 其他启动配置放入此类中
 * @author Lonni
 * @date 2022-09-07 10:15
 */
@Configuration
@EnableConfigurationProperties(ApplicationProperties.class)
public class OtherConfig {

    /**
     * 将long类型转换为string,避免前端精度丢失导致数据不一致
     * @return
     */
    @Bean
    public Jackson2ObjectMapperBuilderCustomizer jackson2ObjectMapperBuilderCustomizer() {
        return jacksonObjectMapperBuilder -> {
            jacksonObjectMapperBuilder.serializerByType(BigInteger.class, ToStringSerializer.instance);
            jacksonObjectMapperBuilder.serializerByType(Long.class, ToStringSerializer.instance);
        };
    }


}
